<?php
/**
 * 业务员
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/2/7
 * Time: 11:51
 */
namespace App\Services\Warehouse;
class TheSalesmanService extends PublicService{
    public function __construct()
    {
        parent::__construct(Config('k3cloud.TheSalesman'));
    }

    /**
     *单据列表查询
     * 1.data：Json格式数据（详情参考Json格式数据）（必录）
    1.1.FormId：业务对象表单Id（必录）
    1.2.FieldKeys：字段keys，字符串类型用逗号分隔，比如"key1,key2..."（必录）
    1.3.FilterString：过滤（非必录）  FNumber=''
    1.4.OrderString：排序字段（非必录）
    1.5.TopRowCount：总行数（非必录）
    1.6.StartRow：开始行（非必录）
    1.7.Limit：最大行数，不能超过2000（非必录）
     */
    public function ExecuteBillQueryTheSalesman($FieldKeys = '', $FilterString = '', $OrderString = '', $TopRowCount = 0, $StartRow = 0, $Limit = 20)
    {
        if (empty($FieldKeys)) {
            $FieldKeys='FOperatorId,FBillNo,FOperatorType,FStaffId.FName,Fdept,FPosition,FIsUse';
        }
        return parent::ExecuteBillQuery($FieldKeys, $FilterString, $OrderString, $TopRowCount, $StartRow, $Limit);
    }

    /**
     * 业务员类型列表
     * */
    public function TheSalesmanTypeList(){
        return $list=[
            'XSY'=>'销售员',
            'CGY'=>'采购员',
            'FWRY'=>'服务人员',
            'WHY'=>'仓管员',
            'ZJY'=>'质检员',
            'CWRY'=>'财务人员',
            'JSY'=>'驾驶员',
            'JHY'=>'计划员'
        ];
    }

    /**
     * 保存
     * 参数说明
     * FOperatorId  业务员ID   默认为0  0表示新增   具体ID 表示修改
     * FOperatorType 业务员类型
     * FNumber  员工编号
     */
    public function SaveTheSalesman($arrdata=[]){
        if(empty($arrdata['FOperatorId'])){
            $arrdata['FOperatorId']=0;
        }
        $data=[
            "FOperatorId"=>$arrdata['FOperatorId'],
            "FOperatorType"=>$arrdata['FOperatorType'],
            "FEntity"=>[
                [
                    "FEntryId"=>null,
                    "FOperatorType_ETY"=>$arrdata['FOperatorType'],
                    "FBizOrgId"=>[
                        "FNumber"=>Config('k3cloud.organization')
                    ],
                    "FStaffId"=>[
                        "FNumber"=>$arrdata['FStaffNumber']
                    ]
                ]
            ]
        ];
    }


    /**
    *  参数说明
     * $FStaffNumber   员工编号
     *
     */
    public function ListTheSalesman($FStaffNumber=''){
        $FieldKeys='FOperatorId,FBillNo,FOperatorType,FStaffId.FNumber,FStaffId.FName,Fdept,FPosition,FIsUse';
        $FilterString='';
        if(!empty($FStaffNumber)){
            $FilterString="FStaffId.FNumber='".$FStaffNumber."'";
        }
        $list=$this->ExecuteBillQuery($FieldKeys,$FilterString);
        if($list){
            return $list;
        }else{
            return false;
        }
    }

}